package com.xique.door.controller;


import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.domain.BuildFloor;
import com.xique.door.service.IBuildFloorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 楼层Controller
 * 
 * @author caogq
 * @date 2021-09-09
 */
@Deprecated
@Controller
@RequestMapping("/build/floor")
public class BuildFloorController extends BaseController
{
    private String prefix = "community/build/floor";

    @Autowired
    private IBuildFloorService buildFloorService;

     @PreAuthorize(hasPermi="build:floor:view")
    @GetMapping("/{parkId}")
    public String floor(@PathVariable("parkId") Long parkId, ModelMap mmap)
    {
        mmap.put("parkId",parkId);
        return prefix + "/floor";
    }

    /**
     * 查询楼层列表
     */
     @PreAuthorize(hasPermi="build:floor:list")
    @PostMapping("/list/{parkId}")
    @ResponseBody
    public TableDataInfo list(BuildFloor buildFloor)
    {
        startPage();
        List<BuildFloor> list = buildFloorService.selectBuildFloorList(buildFloor);
        return getDataTable(list);
    }

    /**
     * 导出楼层列表
     */
     @PreAuthorize(hasPermi="build:floor:export")
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response,BuildFloor buildFloor) throws IOException {
        List<BuildFloor> list = buildFloorService.selectBuildFloorList(buildFloor);
        ExcelUtil<BuildFloor> util = new ExcelUtil<BuildFloor>(BuildFloor.class);
         util.exportExcel(response,list, "floor");
    }

    /**
     * 新增楼层
     */
    @GetMapping("/add/{parkId}")
    public String add(@PathVariable("parkId") Long parkId, ModelMap mmap)
    {
        mmap.put("parkId", parkId);
        return prefix + "/add";
    }

    /**
     * 新增保存楼层
     */
     @PreAuthorize(hasPermi="build:floor:add")
    @Log(title = "楼层", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BuildFloor buildFloor)
    {
        BuildFloor search = new BuildFloor();
        search.setCode(buildFloor.getCode());
        if (!buildFloorService.selectBuildFloorList(search).isEmpty()){
            return AjaxResult.error("编号重复");
        }
        return toAjax(buildFloorService.insertBuildFloor(buildFloor));
    }

    /**
     * 修改楼层
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BuildFloor buildFloor = buildFloorService.selectBuildFloorById(id);
        mmap.put("buildFloor", buildFloor);
        return prefix + "/edit";
    }

    /**
     * 修改保存楼层
     */
     @PreAuthorize(hasPermi="build:floor:edit")
    @Log(title = "楼层", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BuildFloor buildFloor)
    {
        return toAjax(buildFloorService.updateBuildFloor(buildFloor));
    }

    /**
     * 删除楼层
     */
     @PreAuthorize(hasPermi="build:floor:remove")
    @Log(title = "楼层", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(buildFloorService.deleteBuildFloorByIds(ids));
    }
}
